/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.pacs.model;

import com.cxhd.pacs.tools.DateUtil;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Model;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Administrator
 */
public class Asklist extends Model<Asklist> {

    public String saveAsk(Controller con) {

        if (con.getPara("pk") != null) {
            updateAsk(con);
            return con.getPara("pk");
        } else {
            Map<String, String[]> maps = con.getParaMap();
            for (String key : maps.keySet()) {
                set(key, con.getPara(key));
            }
            set("createtime", DateUtil.getDateEN());

            save();
            return get("pk")+"";
        }

    }

    public void updateAsk(Controller con) {
        
        findById(con.getPara("pk"))
                .set("patient_name", con.getPara("patient_name"))
                .set("recvicer_id", con.getPara("recvicer_id"))
                .set("recvicer_name", con.getPara("recvicer_name"))
                  .set("recvicer_phone", con.getPara("recvicer_phone"))
                .set("contact_phone", con.getPara("contact_phone"))
                .set("sender_name", con.getPara("sender_name"))
                .set("description", con.getPara("description"))
                .set("sender_id", con.getPara("sender_id"))
                .set("age", con.getPara("age"))
                .set("patient_id", con.getPara("patient_id"))
                .set("appointment_time", con.getPara("appointment_time")).update();

    }

    public void getAskListRec(String recvicer_id) {

        find("select * from asklist where recvicer_id='" + recvicer_id + "'");

    }

    public void getAskListAsk(String sender_id) {

        find("select * from asklist where sender_id='" + sender_id + "'");

    }
   

}
